package com.mj.listen3.链表;

public class _0_反转双向链表 {
    public DoubleNode reverseList(DoubleNode head) {
        if (head == null || head.next == null) return head;
        DoubleNode newHead = null;
        while (head != null) {
            // 记录下一个节点
            DoubleNode temp = head.next;
            // 当前遍历到的节点的next指向前面
            head.next = newHead;
            // 当前遍历到的节点的pre指向后面
            head.pre = temp;
            // 新的头指向当前节点
            newHead = head;
            // 当前节点指针往下移动
            head = temp;
        }
        return newHead;
    }
}
